<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_source_donate".
 *
 * @property string $id
 * @property string $user_id
 * @property string $donate_type
 * @property string $donate_amount
 * @property string $area_id
 */
class MktSourceDonate extends \yii\db\ActiveRecord
{
    public $parent_area_id;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_source_donate';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'donate_type', 'donate_amount', 'area_id', 'donate_reward'], 'integer'],
            [['parent_area_id'],'safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户编号',
            'donate_type' => '赞助项目类型',        // 多选?
            'donate_amount' => '赞助金额',
            'area_id' => '赞助区域',
            'donate_reward' => '赞助回报',
        ];
    }

    /**
     * @inheritdoc
     * @return MktSourceDonateQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktSourceDonateQuery(get_called_class());
    }

    public function getUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'user_id']);
    }
    
    public function getArea()
    {
        return $this->hasOne(MktArea::className(), ['id' => 'area_id']);
    }

    public function getIndustryPaths()
    {
        return empty($this->industry) ? '' : $this->industry->getPaths();
    }

    public function getAreaPaths()
    {
        return empty($this->area) ? '' : $this->area->getPaths();
    }
    
    static function getDonateTypeOption($key=null)
    {
        $arr = array(
            0 => '孕妈妈',
            1 => '老人',
            2 => '小孩',
            9 => '其它',
        );        
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    static function getDonateRewardOption($key=null)
    {
        $arr = array(
            0 => '提成1%',
            1 => '提成2%',
        );        
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

}
